<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="../css/layui.css">
    <script src="../layui.js"></script>
</head>
<body style="padding: 10px">
    
    
<form class="layui-form" action="#" lay-filter="role_form">
    <input name="id" type="hidden">
    <div class="layui-form-item">
      <label class="layui-form-label">角色名称</label>
      <div class="layui-input-block">
        <input type="text" name="rname" lay-verify="identity" placeholder="" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">描述</label>
      <div class="layui-input-inline">
        <textarea name="rdesc" rows="10" cols="20"></textarea>
      </div>
      <div class="layui-form-mid layui-word-aux">请填写描述信息!</div>
    </div>
    
    
  </form>
 
  
  <script>
  var $;
  layui.use(['form'], function(){
	$ = layui.jquery;
  })
  
  
  function add(type){
	 if($("[name=id]").val()==''){
		 $.post("../RoleServlet",{method:"add",rname:$("[name=rname]").val(),rdesc:$("[name=rdesc]").val()},function(data){
			  if(data == "ok"){
				  parent.layer.closeAll();
				  parent.layer.msg("恭喜,添加成功!!");
			  }
		  })
	 }else{
		 $.post("../RoleServlet",{method:"update",id:$("[name=id]").val(),rname:$("[name=rname]").val(),rdesc:$("[name=rdesc]").val()},function(data){
			  if(data == "ok"){
				  parent.layer.closeAll();
				  parent.layer.msg("恭喜,修改成功!!");
			  }
		  })
	 }
	 
  }
  
  function update_role(obj){
	  layui.use(['form'], function(){
			$ = layui.jquery;
			form = layui.form;
			
			console.log(obj.data);
			form.val("role_form",{id:obj.data.id,rname:obj.data.rname,rdesc:obj.data.rdesc})
	})
	  
	  //form.val("role_form",obj.data)
  }

  </script>



</body>
</html>
